
<?php 
$store = Mage::app()->getStore();
$code  = $store->getCode();
$enable = Mage::getStoreConfig('filterproducts/bestseller/active',$code);
?>
<?php if($enable == 1) { ?>
<div class="block block-bestseller">
    <div class="block-title">
        <strong><span><?php echo Mage::getStoreConfig('filterproducts/bestseller/title',$code); ?></span></strong>
    </div>
    <div class="block-content">
<?php
/**
 * Product list template
 *
 * @see Mage_Catalog_Block_Product_List
 */
?>
<?php
    $_productCollection=$this->getLoadedProductCollection();
    $_productCollection->addAttributeToSelect('news_from_date')
        ->addAttributeToSelect('news_to_date');
    $_helper = $this->helper('catalog/output');
?>
<?php if(!$_productCollection->count()): ?>
<p class="note-msg"><?php echo $this->__('There are no products matching the selection.') ?></p>
<?php else: ?>
<div class="category-products">
    <?php $_iterator = 0; ?>
    <ol class="products-list" id="products-list">
    <?php foreach ($_productCollection as $_prod): ?>
    <?php
        $_product = Mage::getModel('catalog/product')->load($_prod->getId());
    ?>
        <li class="item<?php if( ++$_iterator == sizeof($_productCollection) ): ?> last<?php endif; ?>">
            <?php // Product Image ?>
            <div class="product-image-area" hover_img="<?php echo $this->helper('catalog/image')->init($_product, 'thumbnail')->constrainOnly(FALSE)->keepAspectRatio(TRUE)->keepFrame(FALSE)->resize(100) ?>" base_img="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->constrainOnly(FALSE)->keepAspectRatio(TRUE)->keepFrame(FALSE)->resize(100) ?>" >
                <a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" class="product-image">
                    <img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(100)->constrainOnly(FALSE)->keepAspectRatio(TRUE)->keepFrame(FALSE); ?>" alt="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" />
                </a>
                <?php 
                    $top_position = 10;
                    // Get the Special Price
                    $specialprice = Mage::getModel('catalog/product')->load($_product->getId())->getSpecialPrice(); 
                    // Get the Special Price FROM date
                    $specialPriceFromDate = Mage::getModel('catalog/product')->load($_product->getId())->getSpecialFromDate();
                    // Get the Special Price TO date
                    $specialPriceToDate = Mage::getModel('catalog/product')->load($_product->getId())->getSpecialToDate();
                    // Get Current date
                    $today =  time();
                 
                    if ($specialprice){
                        if($today >= strtotime( $specialPriceFromDate) && $today <= strtotime($specialPriceToDate) || $today >= strtotime( $specialPriceFromDate) && is_null($specialPriceToDate)){
                            if(Mage::getStoreConfig("trego_settings/product_label/sale", $code)){
                ?>
                            <div class="sale-product-icon" style="top: <?php echo $top_position; ?>px"><?php echo $this->__('Sale') ?></div>
                <?php       
                            $top_position += 20;
                            }
                        }
                    }
                ?>
                <?php
                    $now = date("Y-m-d");
                    $newsFrom= substr($_product->getData('news_from_date'),0,10);
                    $newsTo=  substr($_product->getData('news_to_date'),0,10);
                    if ($newsTo != '' || $newsFrom != ''){
                        if (($newsTo != '' && $newsFrom != '' && $now>=$newsFrom && $now<=$newsTo) || ($newsTo == '' && $now >=$newsFrom) || ($newsFrom == '' && $now<=$newsTo))
                        {
                            if(Mage::getStoreConfig("trego_settings/product_label/new", $code)){
                    ?> 
                            <div class="new-product-icon" style="top: <?php echo $top_position; ?>px"><?php echo $this->__('New');?></div>
                    <?php 
                            $top_position += 20;
                            }
                        }
                    }
                ?>
                <div class="clearer"></div>
            </div>
            <?php // Product description ?>
            <div class="product-shop">
                <div class="f-fix">
                    <?php $_productNameStripped = $this->stripTags($_product->getName(), null, true); ?>
                    <h2 class="product-name"><a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $_productNameStripped; ?>"><?php echo $_helper->productAttribute($_product, $_product->getName() , 'name'); ?></a></h2>
                    <?php echo $this->getReviewsSummaryHtml($_product) ?>
                    <?php echo $this->getPriceHtml($_product, true) ?>
                </div>
            </div>
        </li>
    <?php endforeach; ?>
    </ol>
    <script type="text/javascript">decorateList('products-list', 'none-recursive')</script>
</div>
<?php endif; ?>

    </div>
</div>

<?php }  ?>